#include "attendancewin.h"

#include <QApplication>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <SelectWin.h>
#include <opencv.hpp>
#include "registerwin.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //Qt 的信号槽机制要求跨线程传递的自定义类型必须注册，否则无法正确序列化和反序列化,注册 cv::Mat 类型
    qRegisterMetaType<cv::Mat>("cv::Mat&");
    qRegisterMetaType<cv::Mat>("cv::Mat");

    //连接数据库
    QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");

    //设置数据库名称
    db.setDatabaseName("server.db");

    //打开数据库
    if(!db.open())
    {
        qDebug()<<db.lastError().text();
        return -1;
    }

    //创建员工信息表格
    QString createSql="create table if not exists employee(employeeID integer primary key autoincrement,name vachar(256),sex varchar(32),"
                        "birthday text,address text,phone text,faceID integer unique,headfile text)";

    QSqlQuery query;
    if(!query.exec(createSql))
    {
        qDebug()<<query.lastError().text();
        return -1;
    }

    //创建考勤表
    createSql="create table if not exists attendance(attendanceID integer primary key autoincrement,employeeID integer,"
                "attendanceTime TimeStamp NOT NULL DEFAULT(datatime('now','localtime')))";

    if(!query.exec(createSql))
    {
        qDebug()<<query.lastError().text();
        return -1;
    }

    AttendanceWin w;
    w.show();
    // RegisterWin r;
    // r.show();
    // SelectWin sw;
    // sw.show();
    return a.exec();
}
